package com.me.mysqladmin.controller;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class BaseController {
	// 日志记录器
	protected final static Logger LOG = LoggerFactory.getLogger(BaseController.class);
	
	/**
	 * 输出操作成功信息
	 */
	protected Map<String, Object> messageSuccess(Object data){
		return message(true, data, "操作成功！");
	}
	
	/**
	 * 输出操作成功信息
	 */
	protected Map<String, Object> messageSuccess(){
		return message(true, "", "操作成功！");
	}
	
	/**
	 * 输出操作失败信息
	 */
	protected Map<String, Object> messageFailure(Object data, String message){
		return message(false, data, message);
	}

	/**
	 * 输出操作信息
	 * @param success
	 * @param data
	 * @param msg
	 */
	private Map<String, Object> message(boolean success, Object data, String msg) {
		Map<String, Object> map = new HashMap<>();
		map.put("success", success);
		map.put("data", data);
		map.put("message", msg);
		return map;
	}
}
